package com.example.obj;

import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

public class BaseSet<E> {
	private Set<E> Elements;

	public BaseSet(){
		Elements = new HashSet<E>();
	}
	
	public BaseSet(Collection<E> elements){
		Elements = new HashSet<E>(elements);
	}
	
	public Set<E> getElements() {
		return Elements;
	}

	@Override
	public String toString() {
		return "" + Elements + "";
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((Elements == null) ? 0 : Elements.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		@SuppressWarnings("rawtypes")
		BaseSet other = (BaseSet) obj;
		if (Elements == null) {
			if (other.Elements != null)
				return false;
		} else if (!Elements.equals(other.Elements))
			return false;
		return true;
	}

	public BaseSet<E> remove(E element) {
		this.Elements.remove(element);
		return this;
	}
	
	public int size() {		
		return this.Elements.size();
	}

	public BaseSet<E> add(E element) {
		Elements.add(element);
		return this;	
	}

	public E getElement(int number) {
		Iterator<E> iter = Elements.iterator();		
		for (int i = 1; i < number; i++) {
			iter.next();
		}
		return iter.next();
	}
}
